/**
 * 
 *  @project Air Traff Monitor
 * 
 *  @author M.Emre ATASEVER <m.emre.atas@gmail.com>
 *  @author M.Burak ALKAN <mburakalkan@gmail.com>
 *  @author H.Burak KARAMIK <bkaramik@gmail.com>
 *
 *	`Air Traffic Monitor' is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "infoview.h"

QKismetInfoDock::QKismetInfoDock(QKismetSocket *sock) : infownd(sock)
{
	hide();
	
	QAction *a = toggleViewAction();
	a->setIcon(QIcon(":/img/i.svg"));
	a->setStatusTip("Toggle Info window");
	setWindowTitle("Info");

	connect(this,SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),this,SLOT(locationChanged(Qt::DockWidgetArea)));

	setWidget(&infownd);
}

void QKismetInfoDock::locationChanged(Qt::DockWidgetArea area)
{
	infownd.switchOrientation((area == Qt::RightDockWidgetArea || area == Qt::LeftDockWidgetArea));
}


QKismetInfoDock::~QKismetInfoDock()
{
}


QKismetInfoWnd::QKismetInfoWnd(QKismetSocket *sock) : main(QBoxLayout::TopToBottom), bars(QBoxLayout::LeftToRight)
{
	socket		= sock;
	vertical	= true;

	setLayout(&main);
	main.addLayout(&card);
	main.addStretch(0);
	main.addLayout(&bars);

	card.addWidget(&networks);
	card.addWidget(&packets);
	card.addWidget(&crypt);
	card.addWidget(&weak);
	card.addWidget(&noise);
	card.addWidget(&dropped);
	card.addWidget(&rate);
	card.addWidget(&signal);
	
	powerlay 	= new QBoxLayout(QBoxLayout::TopToBottom);
	bars.addLayout(powerlay);
	powerlab.setText("Power");
	powerlay->addWidget(&powerlab);
	powerlay->addWidget(&powerbar);
	
	qualitylay	= new QBoxLayout(QBoxLayout::TopToBottom);
	bars.addLayout(qualitylay);
	qualitylab.setText("Quality");
	qualitylay->addWidget(&qualitylab);
	qualitylay->addWidget(&qualitybar);

	noiselay	= new QBoxLayout(QBoxLayout::TopToBottom);
	bars.addLayout(noiselay);
	noiselab.setText("Noise");
	noiselay->addWidget(&noiselab);
	noiselay->addWidget(&noisebar);

	powerbar.setOrientation(Qt::Vertical);
	qualitybar.setOrientation(Qt::Vertical);
	noisebar.setOrientation(Qt::Vertical);
	
	connect(sock,SIGNAL(infoInfo(iInfo)),this,SLOT(infoInfo(iInfo)));
}

QKismetInfoWnd::~QKismetInfoWnd()
{
	delete	powerlay;
	delete	qualitylay;
	delete	noiselay;
}

void QKismetInfoWnd::infoInfo(iInfo info)
{
	networks.setText("Networks: \t"+info.props[0].toString());
	packets.setText("Packets: \t"+info.props[1].toString());
	crypt.setText("Crypted: \t"+info.props[2].toString());
	weak.setText("Weak: \t"+info.props[3].toString());
	noise.setText("Noise: \t"+info.props[4].toString());
	dropped.setText("Dropped: \t"+info.props[5].toString());
	rate.setText("Packet rate: \t"+info.props[6].toString());
	powerbar.setValue(info.props[7].toInt());
	qualitybar.setValue(info.props[8].toInt());
	noisebar.setValue(info.props[9].toInt());
}

void QKismetInfoWnd::switchOrientation(bool vert)
{
	if(vert == vertical)
		return;
	vertical	= vert;
	if(vert)
	{
		main.setDirection(QBoxLayout::TopToBottom);
		bars.setDirection(QBoxLayout::LeftToRight);
		powerbar.setOrientation(Qt::Vertical);
		qualitybar.setOrientation(Qt::Vertical);
		noisebar.setOrientation(Qt::Vertical);
	}
	else
	{
		main.setDirection(QBoxLayout::LeftToRight);
		bars.setDirection(QBoxLayout::TopToBottom);
		powerbar.setOrientation(Qt::Horizontal);
		qualitybar.setOrientation(Qt::Horizontal);
		noisebar.setOrientation(Qt::Horizontal);
	}
}
